guint i;
if (_gtk_css_parser_try (parser, "none", TRUE))
- return _gtk_css_value_new_take_shadow (NULL);
+ return _gtk_shadow_new_none ();
shadow = _gtk_shadow_new ();
if (!_gtk_css_parser_try_double (parser, &voffset))
{
_gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
- _gtk_shadow_unref (shadow);
+ _gtk_css_value_unref (shadow);
return NULL;
}
if (color == NULL)
{
- _gtk_shadow_unref (shadow);
+ _gtk_css_value_unref (shadow);
return NULL;
}
}
if (!have_color || !have_lengths)
{
_gtk_css_parser_error (parser, "Must specify at least color and offsets");
- _gtk_shadow_unref (shadow);
+ _gtk_css_value_unref (shadow);
return NULL;
}
}
while (_gtk_css_parser_try (parser, ",", TRUE));
- return _gtk_css_value_new_take_shadow (shadow);
-}
-
-static void
-shadow_value_print (GtkCssStyleProperty *property,
- const GtkCssValue *value,
- GString *string)
-{
- GtkShadow *shadow;
-
- shadow = _gtk_css_value_get_shadow (value);
-
- if (shadow == NULL)
- g_string_append (string, "none");
- else
- _gtk_shadow_print (shadow, string);
+ return shadow;
}
static GtkCssValue *
GtkStyleContext *context,
GtkCssValue *specified)
{
- GtkShadow *shadow;
-
- shadow = _gtk_css_value_get_shadow (specified);
- if (shadow)
- shadow = _gtk_shadow_resolve (shadow, context);
-
- return _gtk_css_value_new_take_shadow (shadow);
+ return _gtk_shadow_resolve (specified, context);
}
static GtkCssValue *
G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT,
shadow_value_parse,
- shadow_value_print,
+ NULL,
shadow_value_compute,
NULL,
NULL,
- _gtk_css_value_new_take_shadow (NULL));
+ _gtk_shadow_new_none ());
gtk_css_style_property_register ("icon-shadow",
G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT,
shadow_value_parse,
- shadow_value_print,
+ NULL,
shadow_value_compute,
NULL,
NULL,
- _gtk_css_value_new_take_shadow (NULL));
+ _gtk_shadow_new_none ());
gtk_css_style_property_register ("box-shadow",
G_TYPE_NONE,
0,
shadow_value_parse,
- shadow_value_print,
+ NULL,
shadow_value_compute,
NULL,
NULL,
- _gtk_css_value_new_take_shadow (NULL));
+ _gtk_shadow_new_none ());
gtk_css_style_property_register ("margin-top",
G_TYPE_INT,
return value;
}
-GtkCssValue *
-_gtk_css_value_new_take_shadow (GtkShadow *v)
-{
- GtkCssValue *value;
-
- value = gtk_css_value_new (GTK_TYPE_SHADOW);
- value->u.ptr = v;
-
- return value;
-}
-
GtkCssValue *
_gtk_css_value_new_take_image (GtkCssImage *v)
{
return value->u.ptr;
}
-GtkShadow *
-_gtk_css_value_get_shadow (const GtkCssValue *value)
-{
- g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_SHADOW), NULL);
- return value->u.ptr;
-}
#include "gtkcsstypesprivate.h"
#include "gtksymboliccolor.h"
#include "gtkcssimageprivate.h"
-#include "gtkshadowprivate.h"
+#include "gtkthemingengine.h"
G_BEGIN_DECLS
GtkCssValue *_gtk_css_value_new_from_color (const GdkColor *v);
GtkCssValue *_gtk_css_value_new_take_symbolic_color (GtkSymbolicColor *v);
GtkCssValue *_gtk_css_value_new_take_pattern (cairo_pattern_t *v);
-GtkCssValue *_gtk_css_value_new_take_shadow (GtkShadow *v);
GtkCssValue *_gtk_css_value_new_take_image (GtkCssImage *v);
GtkCssValue *_gtk_css_value_new_from_theming_engine (GtkThemingEngine *v);
GtkCssValue *_gtk_css_value_new_take_binding_sets (GPtrArray *array);
const GdkRGBA *_gtk_css_value_get_rgba (const GtkCssValue *value);
cairo_pattern_t *_gtk_css_value_get_pattern (const GtkCssValue *value);
GtkGradient *_gtk_css_value_get_gradient (const GtkCssValue *value);
-GtkShadow *_gtk_css_value_get_shadow (const GtkCssValue *value);
G_END_DECLS
* GtkShadow *
****************/
-G_DEFINE_BOXED_TYPE (GtkShadow, _gtk_shadow,
- _gtk_shadow_ref, _gtk_shadow_unref)
-
-struct _GtkShadow {
+struct _GtkCssValue {
+ GTK_CSS_VALUE_BASE
GList *elements;
- guint ref_count;
+ gboolean resolved;
};
-GtkShadow *
-_gtk_shadow_new (void)
+static void
+gtk_css_value_shadow_free (GtkCssValue *shadow)
{
- GtkShadow *retval;
-
- retval = g_slice_new0 (GtkShadow);
- retval->ref_count = 1;
+ g_list_free_full (shadow->elements,
+ (GDestroyNotify) shadow_element_free);
+ g_slice_free (GtkShadow, shadow);
+}
- return retval;
+static gboolean
+gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
+ const GtkCssValue *shadow2)
+{
+ /* FIXME */
+ return shadow1 == shadow2;
}
-GtkShadow *
-_gtk_shadow_ref (GtkShadow *shadow)
+static void
+gtk_css_value_shadow_print (const GtkCssValue *shadow,
+ GString *string)
{
- g_return_val_if_fail (shadow != NULL, NULL);
+ gint length;
+ GList *l;
- shadow->ref_count++;
+ length = g_list_length (shadow->elements);
- return shadow;
-}
+ if (length == 0)
+ {
+ g_string_append (string, "none");
+ return;
+ }
-void
-_gtk_shadow_unref (GtkShadow *shadow)
-{
- g_return_if_fail (shadow != NULL);
+ shadow_element_print (shadow->elements->data, string);
- shadow->ref_count--;
+ if (length == 1)
+ return;
- if (shadow->ref_count == 0)
+ for (l = g_list_next (shadow->elements); l != NULL; l = l->next)
{
- g_list_free_full (shadow->elements,
- (GDestroyNotify) shadow_element_free);
- g_slice_free (GtkShadow, shadow);
+ g_string_append (string, ", ");
+ shadow_element_print (l->data, string);
}
}
+static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
+ gtk_css_value_shadow_free,
+ gtk_css_value_shadow_equal,
+ gtk_css_value_shadow_print
+};
+
+static GtkCssValue none_singleton = { >K_CSS_VALUE_SHADOW, 1, NULL, FALSE };
+
+GtkShadow *
+_gtk_shadow_new (void)
+{
+ return _gtk_css_value_new (GtkShadow, >K_CSS_VALUE_SHADOW);
+}
+
+GtkShadow *
+_gtk_shadow_new_none (void)
+{
+ return _gtk_css_value_ref (&none_singleton);
+}
+
void
_gtk_shadow_append (GtkShadow *shadow,
gdouble hoffset,
element->symbolic_color,
&color))
{
- _gtk_shadow_unref (resolved_shadow);
+ _gtk_css_value_unref (resolved_shadow);
return NULL;
}
g_list_append (resolved_shadow->elements, resolved_element);
}
- return resolved_shadow;
-}
-
-void
-_gtk_shadow_print (GtkShadow *shadow,
- GString *str)
-{
- gint length;
- GList *l;
+ resolved_shadow->resolved = TRUE;
- length = g_list_length (shadow->elements);
-
- if (length == 0)
- return;
-
- shadow_element_print (shadow->elements->data, str);
-
- if (length == 1)
- return;
-
- for (l = g_list_next (shadow->elements); l != NULL; l = l->next)
- {
- g_string_append (str, ", ");
- shadow_element_print (l->data, str);
- }
+ return resolved_shadow;
}
void
#include "gtksymboliccolor.h"
#include "gtkicontheme.h"
#include "gtkcsstypesprivate.h"
+#include "gtkcssvalueprivate.h"
#include "gtkroundedboxprivate.h"
G_BEGIN_DECLS
-typedef struct _GtkShadow GtkShadow;
-
-#define GTK_TYPE_SHADOW (_gtk_shadow_get_type ())
-
-GType _gtk_shadow_get_type (void) G_GNUC_CONST;
+typedef GtkCssValue GtkShadow;
GtkShadow *_gtk_shadow_new (void);
-GtkShadow *_gtk_shadow_ref (GtkShadow *shadow);
-void _gtk_shadow_unref (GtkShadow *shadow);
+GtkShadow *_gtk_shadow_new_none (void);
void _gtk_shadow_append (GtkShadow *shadow,
gdouble hoffset,
gboolean inset,
GtkSymbolicColor *color);
-void _gtk_shadow_print (GtkShadow *shadow,
- GString *string);
-
GtkShadow *_gtk_shadow_resolve (GtkShadow *shadow,
GtkStyleContext *context);
_gtk_theming_background_apply_shadow (GtkThemingBackground *bg,
cairo_t *cr)
{
- GtkShadow *box_shadow;
-
- box_shadow = _gtk_css_value_get_shadow (_gtk_style_context_peek_property (bg->context, "box-shadow"));
-
- if (box_shadow != NULL)
- {
- _gtk_box_shadow_render (box_shadow, cr, &bg->padding_box);
- }
+ _gtk_box_shadow_render (_gtk_style_context_peek_property (bg->context, "box-shadow"),
+ cr,
+ &bg->padding_box);
}
static void
fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
}
- text_shadow = _gtk_css_value_get_shadow (_gtk_theming_engine_peek_property (engine, "text-shadow"));
+ text_shadow = _gtk_theming_engine_peek_property (engine, "text-shadow");
prepare_context_for_layout (cr, x, y, layout);
- if (text_shadow != NULL)
- {
- _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
- }
+ _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
gdk_cairo_set_source_rgba (cr, &fg_color);
pango_cairo_show_layout (cr, layout);
radius = MIN (width / 2, height / 2);
gtk_theming_engine_get_color (engine, state, &color);
- shadow = _gtk_css_value_get_shadow (_gtk_theming_engine_peek_property (engine, "icon-shadow"));
+ shadow = _gtk_theming_engine_peek_property (engine, "icon-shadow");
cairo_save (cr);
cairo_translate (cr, x + width / 2, y + height / 2);
- if (shadow != NULL)
- {
- _gtk_icon_shadow_paint_spinner (shadow, cr,
- radius,
- progress);
- }
+ _gtk_icon_shadow_paint_spinner (shadow, cr,
+ radius,
+ progress);
_gtk_theming_engine_paint_spinner (cr,
radius,
gdouble x,
gdouble y)
{
- GtkShadow *icon_shadow;
-
cairo_save (cr);
gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
- icon_shadow = _gtk_css_value_get_shadow (_gtk_theming_engine_peek_property (engine, "icon-shadow"));
-
- if (icon_shadow != NULL)
- {
- _gtk_icon_shadow_paint (icon_shadow, cr);
- }
+ _gtk_icon_shadow_paint (_gtk_theming_engine_peek_property (engine, "icon-shadow"), cr);
cairo_paint (cr);